# -*- coding: utf-8 -*-

import datetime

from mongoengine import *

from people.models import People

class PlaceRank(Document):
    """
    Place rank model
    """
    five_stars  = IntField(default=0)
    four_stars  = IntField(default=0)
    three_stars = IntField(default=0)
    two_stars   = IntField(default=0)
    one_stars   = IntField(default=0)
    average     = IntField(default=0)

class PlaceComment(Document):
    """
    Place comment model
    """
    username = StringField(max_length=16)
    comment = StringField(max_length=300)
    created = DateTimeField(default=datetime.datetime.now)

class PlaceSubject(Document):
    """
    Place subject model
    """
    username    = StringField(max_length=16, required=True)
    place_uid   = StringField(max_length=128)
    description = StringField(max_length=300)
    image       = FileField(required=True)
    thumb       = FileField(required=True)
    created     = DateTimeField(default=datetime.datetime.now)

class PlacePhoto(Document):
    """
    Place photo model
    """
    username    = StringField(max_length=16)
    place_uid   = StringField(max_length=128)
    image       = FileField(required=True)
    thumb       = FileField(required=True)
    created     = DateTimeField(default=datetime.datetime.now)

class Place(Document):
    """
    Place model
    """
    PLACE_GENRE = (
            ('public',u'公开'),
            ('private',u'私人'),
            ('commercial',u'商业'),
            ('unknow', u'不清楚')
            )

    uid         = StringField(max_length=128, required=True)
    country     = StringField(max_length=32, required=True)
    region      = StringField(max_length=32, required=True)
    city        = StringField(max_length=32, required=True)
    district    = StringField(max_length=32, required=True)
    name        = StringField(max_length=32, required=True)
    created     = DateTimeField(default=datetime.datetime.now)
    expire      = DateTimeField()
    genre       = StringField(max_length=10, required=True)
    tags        = ListField(StringField(max_length=64))
    description = StringField(max_length=1000, required=True)
    rank        = ReferenceField(PlaceRank)
    location    = GeoPointField(required=True)
    address     = StringField(max_length=64, required=True)
    discover    = StringField(max_length=16, required=True)
    master      = StringField(max_length=16)
    visitors    = ListField(StringField())
    subjects    = ListField(ReferenceField(PlaceSubject))
    comments    = ListField(ReferenceField(PlaceComment))

    def __unicode__(self):
        return u'%s, %s, %s, %s' % (
                self.name
                , self.genre
                , self.description
                , self.address
                )
